package com.etime.shycourse.controller.coupons;


import com.etime.shy.common.BaseMessage;
import com.etime.shy.common.ListMessage;
import com.etime.shycourse.dto.CouponrangePackageDto;
import com.etime.shycourse.pojo.Packageimportcourse;
import com.etime.shycourse.services.coupons.interfaces.PackageimportcourseServices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 *
 * @author wb
 * @since 2022-03-15
 */
@Api(tags = "后台-课程包-课程信息")
@RestController
@RequestMapping("/sys/packageimportcourse")
public class PackageimportcourseController {
    @Autowired
    private PackageimportcourseServices service;

    @ApiOperation("为课程包分配课程。返回int 成功 =1 失败=0 ")
    @PostMapping("/insert")
    public BaseMessage insertPackageCourse(@RequestBody CouponrangePackageDto dto) {
        BaseMessage msg = new BaseMessage();
        int i = service.insertPackageCourse(dto);
        if (i > 0) {
            msg.setCode(i);
            msg.setMsg("创建课程包范围成功");
        } else {
            msg.setCode(0);
            msg.setMsg("创建课程包范围失敗");
        }
        return msg;
    }

    @ApiOperation("查询可以用课程包的")
    @GetMapping("/list/{packageId}")
    public ListMessage<Packageimportcourse> selectCoursePackageLists(@PathVariable Integer packageId) {
        List<Packageimportcourse> data = service.selectCoursePackageList(packageId);
        ListMessage<Packageimportcourse> msg = new ListMessage<>();
        if (data.size () > 0) {
            msg.setCode (1);
            msg.setDatalist (data);
        } else {
            msg.setCode (0);
            msg.setMsg ("没有课程数据");
        }
        return msg;
    }

}

